package com.yango.logistics;

import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;


@SpringBootApplication
public class LogisticsMainApplication {
    public static void main(String[] args) {
        SpringApplication.run(LogisticsMainApplication.class,args);
    }
    @Bean
    ApplicationRunner applicationRunner(NacosConfigManager nacosConfigManager) {
        return args -> {
            System.out.println("启动时运行");
            ConfigService configService = nacosConfigManager.getConfigService();
            configService.addListener("yjb-service-logistics.properties", "DEFAULT_GROUP",
                    new Listener() {
                        @Override
                        public Executor getExecutor() {
                            return Executors.newFixedThreadPool(3);
                        }

                        @Override
                        public void receiveConfigInfo(String cfg) {
                            System.out.println("===变化的配置信息:：" + cfg);
                            System.out.println("===邮件通知===");
                        }
                    });
        };
    }
}
